

function renderComment() {
    $.ajax({
        url: '/admin/comments',
        success: function (res) {
            // console.log(res);
            let html = template('tpl-list', res);
            $('tbody').html(html);
        }
    });
}
renderComment();


$('body').on('click', 'button:contains("删除")', function () {
    let id = $(this).data('id');
    layer.confirm('确定删除吗?', { icon: 3, title: '提示' }, function (index) {
        $.ajax({
            type: 'delete',
            url: '/admin/comments/' + id,
            success: function (res) {
                layer.msg(res.message);
                if (res.status === 0) {
                    renderComment();
                }
            }
        });

        layer.close(index);
    });
})

template.defaults.imports.timer = function (str) {
    let data = new Date(str);
    let y = data.getFullYear();
    let m = n(data.getMonth() + 1);
    let d = n(data.getDate());
    let h = n(data.getHours());
    let mi = n(data.getMinutes());
    let s = n(data.getSeconds());
    return y + '-' + m + '-' + d + ' ' + h + ':' + mi + ':' + s
}
function n(n) {
    return n < 10 ? '0' + n : n
}

